<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <input type="text" id="txt">
    <ul class="list">
    </ul>
</body>
<script>
    let t = null;

    const otxt = document.querySelector("#txt");
    const olist = document.querySelector(".list");

    
    otxt.onkeyup = function (){
        clearTimeout(t);
        t = setTimeout(() => {
            jsonpBaidu(this.value, res=>{
                let str = "";
                res.g && res.g.forEach(val=>{
                    str += `<li>${val.q}</li>`
                })
                olist.innerHTML = str
            })
        }, 1000);
    }



    function jsonpBaidu(key, cb){
        const script = document.createElement("script")
        script.src = `https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=36545,37353,37300,36885,37403,36569,36786,37243,37258,26350,37371&wd=${key}&req=2&csor=5&pwd=shiy&cb=abc&_=1663748436811`;
        document.body.appendChild(script);

        window.abc = function(res){
            cb(res);
        }
    }

</script>
</html>